package chapter02

object Test35_oparetor {
  def main(args: Array[String]): Unit = {
    val m = List(Map("姓名"->"张三","语文"->87,"数学"->88,"英语"->78),
      Map("姓名"->"李四","语文"->82,"数学"->81,"英语"->90),
      Map("姓名"->"王五","语文"->80,"数学"->74,"英语"->79))
    //计算每门课的平均成绩
    val math = m.map(_.get("数学").head.toString.toInt)
    println(math.sum/math.size)
    //每个人的平均成绩
    val list = m.map(e => {
      e.values.drop(1).map(f=>{f.toString.toInt})
    }).map(e=>{e.sum/e.size})
    val list1 = m.map(_.values.drop(1)
      .map(_.toString.toInt))
      .map(e=>{e.sum/e.size})
    println(list1)
    //所有科目的平均成绩
    val list2 = m.flatMap(_.values.drop(1)
      .map(_.toString.toInt))
    println(list2.sum/list2.size)
  }
}
